package com.lyk.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.common.dao.BaseDao;
import com.common.entity.A_markup;
import com.lyk.dao.A_markupDao;

public class A_markupDaoImpl extends BaseDao<A_markup> implements A_markupDao {

	@Override
	public A_markup findById(Integer n) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from a_markup where markup_id = ? ");
		paramList.add(n);
		List<A_markup> list = findBySql(sf.toString(), paramList.toArray());
		return (list!=null&&list.size()>0)?list.get(0):null;
	}

	@Override
	public int changemarkup(A_markup markup) {
		String sql = "update a_markup set markup_name=?,markup_money=? where markup_id = ?";
		List<Object> paramList=new ArrayList<Object>();
		paramList.add(markup.getMarkup_name());
		paramList.add(markup.getMarkup_money());
		paramList.add(markup.getMarkup_id());
		return this.executeUpdate(sql, paramList.toArray());
	}

	@Override
	public List<A_markup> findByCondition(Map<String, Object> mp) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from a_markup where 1=1 ");
		if(mp!=null && mp.size()>0){
				if(mp.get("atitle")!=null){
					sf.append("and title like ? ");
					paramList.add(mp.get("atitle"));
				}
		}
		return findBySql(sf.toString(), paramList.toArray());
	}
	public A_markup getEntity(ResultSet rs){
		try {
			A_markup markup = new A_markup();
			markup.setMarkup_id(rs.getInt("markup_id"));
			markup.setMarkup_name(rs.getString("markup_name"));
			markup.setMarkup_money(rs.getInt("markup_money"));
			return markup;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
